<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function fun(){
				console.log(`你按下了${event.key},ASCII是${event.keyCode}`)
				if (event.keyCode<48||event.keyCode>57) {
					console.error("不能输入非数字")
					event.preventDefault()
				} else{
					
				}
			}
		</script>
	</head>
	<body>
		请输入数字：<input type="text" onkeypress="fun()"/>
		
	</body>
</html>
